package com.cn.crmsystem.controller.approveController;

import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.approveService.ReimbursementService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@Api(value = "报销api",tags = "报销API")
public class ReimbursementController {
	@Autowired ReimbursementService reimbursementService;
	//查询
	@RequestMapping(value = "/SelectReimbursement",name = "查询报销",method = RequestMethod.POST)
	@ApiOperation(value = "报销查询",notes = "查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "method",value = "我发出的还是我审核",paramType = "query",dataType = "String",required = false)
	})
	@ResponseBody
	public ResultJson selectReimbursement(@RequestParam(name = "userid") Integer userid,
								   @RequestParam(name = "method") String method){
		ResultJson resultJson=new ResultJson();
		resultJson=reimbursementService.SelectMyReimbursement(userid,method);
		return resultJson;
	}
	//修改
	@RequestMapping(value = "/ReimbursementUpdate",name = "修改报销",method = RequestMethod.POST)
	@ApiOperation(value = "修改报销申请",notes = "修改",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "appid",value = "审核id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "state",value = "状态",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson ReimbursementUpdate(@RequestParam(name = "appid") Integer appid,
										   @RequestParam(name = "state") Integer state){
		ResultJson resultJson=new ResultJson();
		resultJson=reimbursementService.UpdateReimbursement(appid,state);
		return  resultJson;
	}
	//删除
	@RequestMapping(value = "/ReimbursementDelete",name = "删除报销",method = RequestMethod.POST)
	@ApiOperation(value = "删除",notes = "更改deleteid",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "appid",value = "审核id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson DeleteReimbursement(@RequestParam(name = "appid") Integer appid){
		ResultJson resultJson=new ResultJson();
		resultJson=reimbursementService.DeleteReimbursement(appid);
		return  resultJson;
	}
	//查询审核人
	@RequestMapping(value = "/selectReimbursementLeader",name = "报销查询审核人",method = RequestMethod.POST)
	@ApiOperation(value = "查询审核人",notes = "查询用户",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson selectReimbursementLeader (@RequestParam(name = "userid")  Integer userid){
		ResultJson resultJson=new ResultJson();
		resultJson=reimbursementService.selectLeader(userid);
		return  resultJson;
	}
	//增加
	@RequestMapping(value = "/InsertReimbursement",name = "增加报销",method = RequestMethod.POST)
	@ApiOperation(value = "新增报销",notes = "插入",httpMethod = "POST", response = String.class)
	@ResponseBody
	public  ResultJson InsertReimbursement (@RequestBody
												@ApiParam(name = "删除",value = "删除",required = false)	Approve AP){
		ResultJson resultJson=new ResultJson();
		Integer leader=AP.getLeader_Id();
		Reimbursement reimbursement=AP.getReimbursement();
		resultJson=reimbursementService.ReimbursementInsert(reimbursement,leader);
		return  resultJson;
	}
	//条件查询
	@RequestMapping(value = "/SelectConditionReimbursement",name = "报销条件查询",method = RequestMethod.POST)
	@ApiOperation(value = "报销条件查询",notes = "条件查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "method",value = "我发出的还是我审核",paramType = "query",dataType = "String",required = false),
			@ApiImplicitParam(name = "state",value = "审核状态",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public  ResultJson SelectConditionReimbursement(@RequestParam(name = "userid") Integer userid,
											   @RequestParam(name = "method") String method,
											   @RequestParam(name = "state") String state ){
		ResultJson resultJson=new ResultJson();
		resultJson=reimbursementService.SelectConditionReimbursement(userid,method,state);
		return resultJson;
	}
}
